package com.xianggu.spring.aop.strategy;

import java.util.List;
import java.util.Objects;

/**
 * @author chengjy
 * @date 2025/3/10
 */
public class WithinPointStrategy implements PointStrategy {

    private Class aClass;
    public WithinPointStrategy(String path) {
        try {
            aClass = Class.forName(path);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("AOP注解路径不存在！" +e);
        }
    }

    @Override
    public boolean match(Class targetClass, List<String> noProxyMethods) {
        if(targetClass.isAnnotationPresent(aClass)){
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return "WithinPointStrategy{" +
                "aClass=" + aClass +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof WithinPointStrategy that)) return false;

        return o.toString().equals(this.toString());
    }

    @Override
    public int hashCode() {
        return aClass != null ? aClass.hashCode() : 0;
    }
}
